package org.flower.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.flower.dao.AddressDao;
import org.flower.dao.impl.AddressDaoImpl;
import org.flower.entity.Address;
import org.flower.entity.User;

/**
 * @author Aizen
 */
@WebServlet(urlPatterns = "/user/addressServlet.shtml")
public class AddRessSer extends HttpServlet {

	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 拿到用户id
		User user = (User) request.getSession().getAttribute("user");
		AddressDao addRess = new AddressDaoImpl();
		List<Address> add = addRess.getAllAddressByUid(user.getId());
		// 获取手机号把中间的四位变成*号
		for (Address aRess : add) {
			String resj = aRess.getPhone();
			int length = resj.length();
			resj = resj.substring(0, 3) + "****" + resj.substring(length - 4);
			aRess.setPhone(resj);
		}
		request.getSession().setAttribute("ress", add);
		request.getRequestDispatcher("../address.jsp").forward(request, response);
	}

}
